//------------------------------------------------------------------------------ 
//  <copyright file="ImageLine.h" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//  </copyright>
//------------------------------------------------------------------------------
#pragma once
#include <vt_edgedetect.h>
#include <vt_linedetector.h>
#include "IShape2D.h"

using namespace System;
using namespace System::Collections::Generic;

namespace Microsoft 
{
    namespace Robotics 
    {
        namespace Vision 
        {
			/// <summary>
			/// Managed version of the line segment returned by VisionTools
			/// </summary>
			public ref struct ImageLine : IShape2D
            {
				/// <summary> X coordinate of start point of the line segment</summary>
				double StartX;

				/// <summary> Y coordinate of start point of the line segment</summary>
				double StartY;

				/// <summary> X coordinate of endpoint of the line segment </summary>
				double EndX;

				/// <summary> Y coordinate of endpoint of the line segment </summary>
				double EndY;

				/// <summary> Geometric length </summary>
				double Length;      

				/// <summary> Average strength of edge pixels </summary>
				double AverageEdgeStrength;

				/// <summary> Variance of edge pixel edgel strength </summary>
				double VarEdgeStrength;

				/// <summary> Mean edgel deviation from line </summary>
				double MeanEdgelDeviation;

				/// <summary> Variance of edgel deviation from line </summary>
				double VarEdgelDeviation;

				/// <summary> Gets  X coordinate line center </summary>
                virtual property double CenterX
				{
					double get()
					{
						return (this->StartX + this->EndX) / 2.0;
					}
			   }

				/// <summary> Gets Y coordinate line center </summary>
                virtual property double CenterY
				{
					double get()
					{
						return (this->StartY + this->EndY) / 2.0;
					}
				}

				/// <summary>Gets or sets the 1D size of Line. </summary>
			   virtual property double Size1D
				{
					double get()
					{
						double x = this->StartX - this->EndX;
						double y = this->StartY - this->EndY;
						return Math::Sqrt(x * x + y * y);
					}
			   }

			   /// <summary> Gets line confidence </summary>
				virtual property double Confidence { double get() { return this->AverageEdgeStrength;} }

				/// <summary> Construct from a native version </summary> 
				ImageLine(vt::LineSegment *pLine)
				{
					this->StartX = pLine->start.x;
					this->StartY = pLine->start.y;
					this->EndX = pLine->end.x;
					this->EndY = pLine->end.y;
					this->Length = pLine->length;
					if (pLine->length < 0)
					{
						this->Length = 0;
					}

					this->AverageEdgeStrength = pLine->avgStrength;
					this->VarEdgeStrength = pLine->varStrength;
					this->MeanEdgelDeviation = pLine->meanDeviation;
					this->VarEdgelDeviation = pLine->varDeviation;
				}
            };
        }
    }
}
